Skip to content

Conversation

tqwewe
Copy link

@tqwewe tqwewe commented Oct 6, 2025

Fixes #6243 - Strange behavior for duplicate imports with imports_granularity="Module"

Problem

When using imports_granularity="Module", duplicate imports were being merged but not deduplicated, requiring multiple formatting passes to reach a stable state. This was inconsistent with other granularity settings which properly remove duplicates.

Solution

Added .dedup() calls after sorting import lists in three locations:

  • merge_rest() - when creating merged import lists
  • UseTree::normalize() - when normalizing nested imports
  • merge_use_trees_inner() - when merging use trees

This ensures duplicate imports are removed in a single formatting pass, matching the behavior of Crate and Item granularity settings.

Test Changes

Updated tests/target/multiple.rs to expect deduplicated imports. I believe the previous test was documenting the buggy behavior rather than the expected behavior.

Example

Before (unstable, requires 2 passes):

use risingwave_batch::executor::{BoxedExecutor, JoinType};
use risingwave_batch::executor::{BoxedExecutor, JoinType};
// First pass: {BoxedExecutor, BoxedExecutor, JoinType, JoinType}
// Second pass: {BoxedExecutor, JoinType}

After (stable, single pass):

use risingwave_batch::executor::{BoxedExecutor, JoinType};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strange behavior for duplicate imports with imports_granularity="Module"
2 participants